package com.dk.controller;


import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.pojo.TContentCategory;
import com.dk.service.ITContentCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 广告类型表 前端控制器
 * </p>
 *
 * @author author
 * @since 2021-10-29
 */
@RestController
@RequestMapping("/t-content-category")
@Api(value = "广告类型接口")
public class TContentCategoryController {

    @Autowired
    private ITContentCategoryService contentCategoryService;

    //根据ID查询
    @GetMapping("/{id}")
    @ApiOperation(value = "广告类型查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "广告类型id",required = true,paramType = "path")
    })
    public Result findById(@PathVariable("id") Long id){ //@RequestBody  接收前台以json格式传进来的参数

        TContentCategory category = contentCategoryService.getById(id);

        return Result.bulid(ConstantEnum.SUCCESS).setResult(category);
    }

    //增加
    @PostMapping("/{name}")
    @ApiOperation(value = "广告类型增加接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "广告类型名称",required = true,paramType = "path")
    })
    public Result add(@PathVariable("name") String name){
        TContentCategory category = new TContentCategory();
        category.setName(name);
        contentCategoryService.save(category);
        return Result.bulid(ConstantEnum.SUCCESS);
    }


    //修改
    @PutMapping("/{id}/{name}")
    @ApiOperation(value = "广告类型修改接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "广告类型id",required = true,paramType = "path"),
            @ApiImplicitParam(name = "name",value = "广告类型名称",required = true,paramType = "path")
    })
    public Result update(@PathVariable("id") Long id,@PathVariable("name") String name){
        TContentCategory category = new TContentCategory();
        category.setId(id);
        category.setName(name);
        contentCategoryService.updateById(category);
        return Result.bulid(ConstantEnum.SUCCESS);
    }

    //删除
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "广告类型批量删除接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "广告类型id",required = true,paramType = "path")
    })
    public Result delete(@PathVariable("ids") Long[] ids){
        contentCategoryService.removeByIds(Arrays.asList(ids));
        return Result.bulid(ConstantEnum.SUCCESS);
    }

    //全部查询
    @RequestMapping(value = "findAll",method = RequestMethod.GET)
    @ApiOperation(value = "广告类型全部查询接口")
    public Result findAll(){
        List<TContentCategory> list = contentCategoryService.list();
        return Result.bulid(ConstantEnum.SUCCESS).setResult(list);
    }

}
